package com.shf.threads;

public class Runnables implements Runnable{
	
	private int count = 100 ;//火车票数
	
	public static void main(String[] args) {

		Runnables runnables = new Runnables();
		
		Thread thread = new Thread(runnables,"张三");
		Thread thread2 = new Thread(runnables,"李四");
		Thread thread3 = new Thread(runnables,"王五");
		
		thread.start();
		thread2.start();
		thread3.start();
		
	}

	@Override
	public void run() {
		while (count > 0) {
			synchronized (this) {
				count--;
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				try {
					wait(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				if(count % 5 == 0){
					System.out.println(" count="+count+Thread.currentThread().getName());
				}
			}
			
		}
	}

}
